package com.bangbang.controller;


import com.bangbang.configresult.Result;
import com.bangbang.configresult.ResultEnum;
import com.bangbang.pojo.TbAdvertisingOrder;
import com.bangbang.service.ITbAdvertisingOrderService;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

import java.util.Date;
import java.util.List;

/**
 * <p>
 * 广告订单表 前端控制器
 * </p>
 *
 * @author ${author}
 * @since 2021-08-14
 */
@RestController
@RequestMapping("/groupCourse/tbAdvertisingOrder")
public class TbAdvertisingOrderController {

    @Autowired
    private ITbAdvertisingOrderService orderService;

    @ApiOperation("订单接口")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "trade_no", name = "订单流水号", required = true, paramType = "query"),
            @ApiImplicitParam(value = "out_trade_no", name = "订单号", required = true, paramType = "query")
    })
    @PostMapping("createOrder")
    public Result createOrder(@RequestParam("trade_no")String trade_no, @RequestParam("out_trade_out")String out_trade_out){
        //完善订单信息 修改状态、交易完成时间、贸易号（流水号）
        TbAdvertisingOrder order = orderService.selectByOrderId(out_trade_out);
        long l = Long.parseLong(trade_no + "");
        order.setOrderPaymentTime(new Date()).setOrderStatus("1").setOrderRunning(l);
        //保存订单
        orderService.updateById(order);
        return Result.buildResult(ResultEnum.SUCCESS);
    }

    @ApiOperation("订单查询接口")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "out_trade_no", name = "订单号", required = true, paramType = "query")
    })
    @GetMapping("queryOrder")
    public Result queryOrder(@RequestParam("out_trade_out")String out_trade_out){
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.eq("order_running",out_trade_out);
        List<TbAdvertisingOrder> orderList = orderService.list(wrapper);
        return Result.buildResult(ResultEnum.SUCCESS).setResult(orderList);
    }



}

